package com.ymttest.database.annotation.cardservice;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface CardServiceMapper {
	//card table

	@Select("select * from card where cardId = #{cardId}")
	public Map<String, Object> selectCardByCardId(@Param("cardId") String cardId);

	@Update("update card set userId = 0, userName = '', Status =4 ,BindingTime = '1990-01-02' , EndTime = '2030-01-02',Denomination=1000,AvailAmount=1000 where cardId = #{cardId}")
	public int updateCardAsOrigByCardId(@Param("cardId") String cardId);

	@Update("update card set userId = 0, userName = '', Status =#{status} ,BindingTime = '1990-01-02' where cardId = #{cardId}")
	public int updateCardStatusByCardId(@Param("cardId") String cardId,
			@Param("status") int status);

	@Update("update card set denomination = #{amount}, availAmount = #{amount} where cardId = #{cardId}")
	public int updateCardAmountByCardId(@Param("cardId") String cardId,
			@Param("amount") double amount);

	@Update("update card set endTime = #{endTime} where cardId = #{cardId}")
	public int updateCardEndTimeByCardId(@Param("cardId") String cardId,
			@Param("endTime") Date endTime);

	//card batch
	@Select("select * from card_batch where batchId = #{batchId}")
	public Map<String, Object> selectCardBatchByCardBatchId(
			@Param("batchId") int batchId);

	@Select("select * from card_batch as a LEFT JOIN card as b on a.BatchId = b.BatchId where b.CardId = #{cardId}")
	public Map<String, Object> selectCardBatchByCardId(
			@Param("cardId") String cardId);

	//Card entry
	@Select(" SELECT * FROM card_entry WHERE CardId=#{cardId} and BizCode=#{bizCode} and BizNo=#{bizNo} LIMIT 1")
	public Map<String, Object> selectCardEntryByCardIdAndBizCodeAndBizNo(
			@Param("cardId") String cardId, @Param("bizCode") int bizCode,
			@Param("bizNo") String bizNo);

	@Select(" SELECT * FROM card_entry WHERE UserId=#{userId} and BizNo=#{bizNo} order by EntryId desc")
	public List<Map<String, Object>> selectCardEntryByUserId(
			@Param("userId") int userId, @Param("bizNo") String bizNo);

}
